﻿using MvcSimplyCleverPart3.Models;
using MvcSimplyCleverPart3.Code;
using SimplyCleverMiddleTier;
using System.Web.Mvc;
using MvcSimplyCleverResources;

namespace MvcSimplyCleverPart3.Controllers
{
    [LocalizableControllerName(typeof(SimplyCleverResources), "ControllerContact")]
    public class ContactController : Controller
    {

        [SetDefaultValue]
        [LocalizableActionName(typeof(SimplyCleverResources), "ControllerContactIndex")]
        public ActionResult Index()
        {
            return View("Index");
        }



        [HttpPost]
        [LocalizableActionName(typeof(SimplyCleverResources), "ControllerContactSave")]
        public ActionResult Save(AddressViewModel address)
        {
            if (!ModelState.IsValid)
                return View("Index", address);

            CountryProvider.Save(address.Cast());
            var list = CountryProvider.GetUserAddresses().Cast();

            return View("List", list);

        }

        [LocalizableActionName(typeof(SimplyCleverResources), "ControllerContactList")]
        public ActionResult List()
        {
            var list = CountryProvider.GetUserAddresses().Cast();
            return View("list",list);
        }
    }
}
